/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rw.table;

import com.rw.table.formatter.ICellFormatter;
import com.rw.table.render.ICellRenderer;
import java.awt.Color;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableModel;

/**
 *
 * @author Rene Tapia
 */
public class TableRenderer implements TableCellRenderer {

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        TableModel model = table.getModel();
        if (model instanceof ATableModel) {
            ATableModel tableModel = (ATableModel) model;
            ICellRenderer renderer = tableModel.getRenderer(row, column);
            ICellFormatter formatter = tableModel.getFormatter(row, column);
            Color bg = tableModel.getBackground(row, column);
            TableInfo info = new TableInfo(table, value, isSelected, hasFocus, row, column, formatter, bg);
            return renderer.getComponent(info);
        } else {
            throw new RuntimeException("El modelo no es instancia de 'ATableModel'");
        }
    }
}
